<?php require("admin-header.php");

if(isset($OJ_LANG)){
    require_once("../lang/$OJ_LANG.php");
}

echo "<title>用户列表</title>";
echo "<center><h2>用户列表</h2></center>";
require_once("../include/set_get_key.php");
$sql="";
if(isset($_GET['keyword'])){
	$keyword=$_GET['keyword'];
	$keyword="%$keyword%";
	 $sql="select `user_id`,`nick`,`accesstime`,`access_ip`,`school`,`defunct`, `zzstaus` FROM `users` where CONCAT(`user_id`, `nick`, `school`) like ?";
	 $result=pdo_query($sql, $keyword);
}else{
     $sql="select `user_id`,`nick`,`accesstime`,`access_ip`,`school`,`defunct`, `zzstaus` FROM `users`  order by `accesstime` desc limit 100 ";
	 $result=pdo_query($sql);
}
?>
<form action=user_list.php class=center>
    <input name=keyword style="height:30px;" placeholder="请输入用户信息">
    <select name=atzz style="width:100px;height:29px;">
        <option value ="0">未参加</option>
        <option value ="1">学习中</option>
        <option value ="2">已暂停</option>
        <option value ="3">已结业</option>
        <option value="-1" selected>不限</option>
    </select>
    <input type=submit value="<?php echo $MSG_SEARCH?>" >
</form>

<?php
echo "<center><table class='table table-striped' width=90% border=1>";
echo "<tr><td>ID<td>用户名<td>用户状态<td>在机构的状态<td>学校<td>最近登录时间<td>最后一次登录IP";
echo "</tr>";

$isAdmin = isset($_SESSION['administrator']) && $_SESSION['administrator'] == 1;
foreach($result as $row){
        echo "<tr>";
        echo "<td><a href='../userinfo.php?user=".$row['user_id']."'>".$row['user_id']."</a>";
        echo "<td>".$row['nick'];
        $cid=$row['user_id'];
        if( $isAdmin ){
            echo "<td><a href=user_df_change.php?cid=".$row['user_id']."&getkey=".$_SESSION['getkey'].">".($row['defunct']=="N"?"<span class=green>Available</span>":"<span class=red>Reserved</span>")."</a>";
        }else{
            echo "<td>No permissions";
        }

        $zzstatusStr = "";
        switch($row['zzstaus'])
        {
            case 0:
                $zzstatusStr = "未参加";
                break;

            case 1:
                $zzstatusStr = "<span class=green>学习中<span>";
                break;

            case 2:
                $zzstatusStr = "已暂停";
                break;

            case 3:
                $zzstatusStr = "已结业";
                break;
        }
        echo "<td>".$zzstatusStr;

        echo "<td>".$row['school'];
        echo "<td>".$row['accesstime'];
        echo "<td>".$row['access_ip'];
        echo "</tr>";
}
echo "</table></center>";
require("../oj-footer.php");
?>
